import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/6/2
 */
public class FairLock implements Runnable {

    public static ReentrantLock lock = new ReentrantLock(true);

    @Override
    public void run() {
        while (true) {
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName());
            }finally {
                lock.unlock();
            }
        }
    }


    public static void main(String[] args) {
        FairLock r = new FairLock();
        Thread t1 = new Thread(r,"t1");
        Thread t2 = new Thread(r,"t2");
        t1.start();
        t2.start();
    }
}
